//
//  NewQianbaoJiLuViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/27.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewShengChengPlanViewController.h"
#import "JTCSM.h"
#import "NewPlanListTableViewCell.h"
#import "MyDoubleLabelView.h"
#import "NewPlanDuanxinViewController.h"

@interface NewShengChengPlanViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UIView *backview;
    NSMutableArray *titlearray;
}
@property (nonatomic,strong) MyDoubleLabelView *headerDoubleView;
@property (nonatomic,strong) UITableView *tableview;

@end

@implementation NewShengChengPlanViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    [df isRemoveTarbar:YES];
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    [self layoutTableView];
}
- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight)];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.tableHeaderView = [self layouHeaderViewWithFirstName:@"民生银行（3443）" firstimage:@"" secondname:@"民生银行（3443）" secondimage:@""];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _tableview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (UIView *)layouHeaderViewWithFirstName:(NSString *)firstname firstimage:(NSString *)firstimage secondname:(NSString *)secondname secondimage:(NSString *)secondimage{
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 120)];
    backview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    backview.userInteractionEnabled = YES;
    
    UIView * showView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, backview.LC_width-20, backview.LC_height-20)];
    showView.backgroundColor = [UIColor whiteColor];
    [df layerWithView:showView radius:4 width:0 color:nil];
    [backview addSubview:showView];
    
    CGFloat space = 20;
    CGFloat banklogoImagesize = 40;
    CGFloat zhixiangImageWidth = 80;
    CGFloat zhixiangImageHeight = zhixiangImageWidth*0.161347;
    CGFloat changespace = (showView.LC_width-2*space-2*banklogoImagesize-zhixiangImageWidth)/4;
    NSString *str = @"测试数据";
    CGFloat font = 14;
    CGRect rect  = [df labelHeightWithContent:str height:30 font:font];
    CGFloat changetop = 15;
    CGFloat banktop = (showView.LC_height-banklogoImagesize-rect.size.height-changetop)/2;
    
    UIImageView *firstimagev = [[UIImageView alloc]initWithFrame:CGRectMake(space+changespace, banktop, banklogoImagesize, banklogoImagesize)];
    firstimagev.image = [UIImage imageNamed:firstimage];
    [showView addSubview:firstimagev];
    
    UILabel *firstlabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(firstimagev)+changetop, KCONTROLLERWith/2, rect.size.height) text:firstname font:font textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [showView addSubview:firstlabel];
    
    
    UIImageView *zhixiangimagev = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(firstimagev)+changespace, showView.LC_height/2-zhixiangImageHeight, zhixiangImageWidth, zhixiangImageHeight)];
    zhixiangimagev.image = [UIImage imageNamed:@"bank箭头.png"];
    [showView addSubview:zhixiangimagev];
    UILabel *alertLabel = [UILabel initWithFrame:CGRectMake(zhixiangimagev.LC_x, showView.LC_height/2, zhixiangImageWidth, zhixiangImageHeight) text:@"向该银行还款" font:11 textAlignment:NSTextAlignmentRight texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
    [showView addSubview:alertLabel];
    
    
    UIImageView *secondimagev = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(alertLabel)+changespace, banktop, banklogoImagesize, banklogoImagesize)];
    secondimagev.image = [UIImage imageNamed:secondimage];
    [showView addSubview:secondimagev];
    
    UILabel *secondlabel = [UILabel initWithFrame:CGRectMake(KCONTROLLERWith/2, KVIEW_Y(secondimagev)+changetop, KCONTROLLERWith/2, rect.size.height) text:secondname font:font textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [showView addSubview:secondlabel];
    
    
    
    
    
    
    
    return backview;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    NewPlanListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[NewPlanListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    [cell setValueWithModel:indexPath];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 80;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 80)];
    backview.backgroundColor = [UIColor clearColor];
    backview.userInteractionEnabled = YES;
    UIButton *tijiaobutton = [UIButton buttonWithType:UIButtonTypeCustom];
    tijiaobutton.frame = CGRectMake(25, 30, KCONTROLLERWith-40, 50);
    [tijiaobutton addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
    [df layerWithView:tijiaobutton radius:25 width:0 color:nil];
    tijiaobutton.backgroundColor = KZhuTiRGB;
    [tijiaobutton setTitleColor:RGBACOLOR(51, 51, 51, 1) forState:UIControlStateNormal];
    [tijiaobutton setTitle:@"提交计划" forState:UIControlStateNormal];
    [backview addSubview:tijiaobutton];
    return backview;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
- (void)tijiao{
    [self alertView];

}

- (void)theRequest{
    [titlearray removeAllObjects];
    titlearray = nil;
    titlearray = [NSMutableArray array];
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"CreditCard/index") withDict:@{@"token":KTokenString} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            
            [_tableview reloadData];
        }
    }];
}

- (void)alertView{
    backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWidth, KSCREENHeight)];
    backview.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
    backview.userInteractionEnabled = YES;
    [[JTCSMSingle shareSingle].theWindow addSubview:backview];
    UIView *showview = [[UIView alloc]initWithFrame:CGRectMake(55, 0, backview.LC_width-110, 30)];
    showview.backgroundColor = [UIColor whiteColor];
    showview.userInteractionEnabled = YES;
    [backview addSubview:showview];
    [df layerWithView:showview radius:10 width:0 color:nil];
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(0, 0, showview.LC_width, 44) text:@"计算规则" font:15 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:KZhuTiRGB];
    [showview addSubview:titleLabel];
    
    CGRect rect = [df labelHeightWithContent:@"测试" width:100 font:14];
    NSArray *array = @[@"付款卡余额大于还款金额8%；",@"每笔还款金额根据系统自动生成，生成金额不高于还款金额6%；",@"手续费按照还款金额0.8%+0.2元计算；",@"因付款银行卡扣款失败，则自动终止还款计划；"];
    
    CGFloat space = 24;
    CGFloat orginY = titleLabel.LC_height+space;
    for (int i = 0; i <array.count; i++) {
        CGFloat viewsize = 10;
          UILabel *label = [UILabel initWithFrame:CGRectMake(0, 0, showview.LC_width-50-viewsize, 20) text:array[i] font:14 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"666666" alpha:1] backgroundColor:nil];
        [showview addSubview:label];
        CGFloat height = (i ==0)?rect.size.height:[df getSpaceLabelLineSpacing:9 withFont:[UIFont systemFontOfSize:14] withLabel:label];
        label.frame = CGRectMake(viewsize+30, orginY, label.LC_width, height);
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(20, label.LC_y+(rect.size.height-viewsize)/2, viewsize, viewsize)];
        view.backgroundColor = KZhuTiRGB;
        [df layerWithView:view radius:viewsize/2 width:0 color:nil];
        [showview addSubview:view];
        orginY +=height+space;
    }
    
    [df newlineViewWithHeightofTop:orginY superView:showview spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
    
    UILabel *buttonLabel = [UILabel initWithFrame:CGRectMake(0, orginY, showview.LC_width, 44) text:@"知道了" font:15 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:[UIColor whiteColor]];
    buttonLabel.userInteractionEnabled = YES;
    [showview addSubview:buttonLabel];
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotoNextVC) andaddView:buttonLabel];
    
    showview.frame = CGRectMake(55, (KSCREENHeight-orginY-44)/2, showview.LC_width, orginY+44);

}
- (void)gotoNextVC{
    [backview removeFromSuperview];
    NewPlanDuanxinViewController *vc = [[NewPlanDuanxinViewController alloc]init];
    vc.nameTitle = @"短信验证";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

